const BASEURL = 'http://api-hmugo-web.itheima.net/api/public/v1/'

/**
 * 函数对象参数解构，如果要赋默认值，记得使用 =
 * @param {*} obj
 * @returns
 */
function request ({ url, method = 'GET', data = {}, header = {} }) {
  return new Promise((resolve, rejct) => {
    uni.showLoading({
      title: '拼命加载中...'
    })

    uni.request({
      url: `${BASEURL}${url}`,
      method,
      data,
      header,
      success: res => {
        resolve(res.data)
      },
      fail: err => {
        reject(err)
      },
      complete: () => {
        uni.hideLoading()
      }
    })
  })
}

uni.$request = request
